package com.light.applet.oauth.security.jwt;

import com.light.applet.oauth.security.jwt.custom.CustomAccessTokenConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @author weibiao
 */
@Configuration
public class TokenStoreConfig {

    @Bean
    public TokenStore jwtTokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        // 采用自定义转换器，重写源码，解析用户信息
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        CustomAccessTokenConverter accessTokenConverter = new CustomAccessTokenConverter();
        converter.setAccessTokenConverter(accessTokenConverter);
        converter.setSigningKey("wanting@2024");
        return converter;
    }

    @Bean
    public TokenEnhancer jwtTokenEnhancer() {
        return new TokenJwtEnhancer();
    }

}
